package day16.myreflect03;

import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * @author Xiao
 * @date 2021/8/10
 */
public class FieldDemo01 {
    /**
     * 获取Field对象
     * 	Field[] getFields()：返回所有公共成员变量对象的数组
     * 	Field[] getDeclaredFields()：返回所有成员变量对象的数组
     * 	Field getField(String name)：返回单个公共成员变量对象
     * 	Field getDeclaredField(String name)：返回单个成员变量对象
     */
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> clazz = Class.forName("day16.myreflect03.Student03");
        /**返回所有公共成员变量对象的数组*/
        Field[] fields = clazz.getFields();
        /**返回所有成员变量对象的数组*/
        Field[] declFields = clazz.getDeclaredFields();
        /**返回单个公共成员变量对象*/
        Field name = clazz.getField("name");
        Field age = clazz.getField("age");
        /**返回单个成员变量对象*/
        Field gender = clazz.getDeclaredField("gender");
        Field money = clazz.getDeclaredField("money");
        System.out.println(Arrays.toString(fields));
        System.out.println(Arrays.toString(declFields));
        System.out.println(name);
        System.out.println(age);
        System.out.println(gender);
        System.out.println(money);
    }
}
